<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="back/include :: header('新增轮播图')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-carousel-add">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">标题：</label>
                    <div class="col-sm-8">
                        <input name="title" class="form-control" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">类型：</label>
                    <div class="col-sm-8">
                        <select name="wType" class="form-control m-b" th:with="type=${@dict.getType('sys_carousel')}">
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">图片：</label>
                    <div class="col-sm-8">
                        <input name="img" id="img" class="form-control" type="hidden">
                        <a id="url"><img th:src="*{img}" style="width:90px;height:90px;"></a>
                        <input type="file" name="file" id="imgs"/>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="back/include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "custom/carousel"
        $("#form-carousel-add").validate({
            focusCleanup: true
        });

        $("#imgs").change(function(){
            var data = new FormData();
            data.append("file",$("#imgs")[0].files[0]);
            $.ajax({
                type: "post",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function(result) {
                    if(result.code == web_status.SUCCESS) {
                        $("#url img").attr("src", result.fileName)
                        $("#img").val(result.fileName)
                    }else {
                        $.modal.alertError(result.msg);
                    }
                },
                errer: function (error) {
                    $.modal.alertWarning("图片上传失败！");
                }
            })
        })

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-carousel-add').serialize());
            }
        }
    </script>
</body>
</html>